package com.ice.base.result;

import lombok.Data;

import java.util.HashMap;

@Data
public class AjaxResult<T> {

    private Integer status;
    private String msg;
    private T data;
    private HashMap<String, Object> pageInfo;

    public AjaxResult() {
        super();
    }

    public AjaxResult(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    /**成功但不带数据**/
    public static AjaxResult success(){
        return success(null);
    }

    public static AjaxResult success(Object data) {
        AjaxResult result = new AjaxResult();
        result.setStatus(ResultCodeEnum.DO_SUCCESS.getCode());
        result.setMsg(ResultCodeEnum.DO_SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    /**自定义失败**/
    public static AjaxResult error(String msg){
        AjaxResult result = new AjaxResult();
        result.setStatus(ResultCodeEnum.DO_FAILED.getCode());
        result.setMsg(msg);
        return result;
    }


    /**默认失败**/
    public static AjaxResult error(){
        AjaxResult result = new AjaxResult();
        result.setStatus(ResultCodeEnum.DO_FAILED.getCode());
        result.setMsg(ResultCodeEnum.DO_FAILED.getMessage());
        return result;
    }



    @Override
    public String toString() {
        return "Result{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
